package com.alpaak.aspect;

import com.alpaak.common.utils.ThreadContext;
import com.alpaak.common.utils.log.Log4jUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class rvtLogAspect {

	// 匹配com.ewell.sleepcare.controller包下所有类的、
	// 所有方法的执行作为切入点
	@AfterReturning(returning = "rvt",
			pointcut = "execution(* com.alpaak.service.*.*(..))")
	// 声明rvt时指定的类型会限制目标方法必须返回指定类型的值或没有返回值
	// 此处将rvt的类型声明为Object，意味着对目标方法的返回值不加限制
	public void afterServiceMethod(JoinPoint jp, Object rvt) {
		Signature signature= jp.getSignature();
//		Log4jUtil.debug("DeclaringType:" + signature.getDeclaringType());   
//		Log4jUtil.debug("DeclaringTypeName:" + signature.getDeclaringTypeName());  
//		Log4jUtil.debug("Modifiers:" + signature.getModifiers());  
//		Log4jUtil.debug("Name:" + signature.getName());  
//		Log4jUtil.debug("LongString:" + signature.toLongString());  
//		Log4jUtil.debug("ShortString:" + signature.toShortString());  
		
		String token = (String)(ThreadContext.getContext().get("token"));
		Log4jUtil.info("Doing["+token+"]中"+signature.getDeclaringTypeName()+"的"+signature.getName()+"方法,返回:" + rvt);
	}
}
